package com.stylefeng.guns.modular.silk.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Modern;
import com.stylefeng.guns.modular.silk.service.IModernService;

/**
 * 当代丝绸管理控制器
 *
 * @author fengshuonan
 * @Date 2018-04-27 15:03:08
 */
@Controller
@RequestMapping("/modern")
public class ModernController extends BaseController {

    private String PREFIX = "/silk/modern/";

    @Autowired
    private IModernService modernService;

    /**
     * 跳转到当代丝绸管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "modern.html";
    }

    /**
     * 跳转到添加当代丝绸管理
     */
    @RequestMapping("/modern_add")
    public String modernAdd() {
        return PREFIX + "modern_add.html";
    }

    /**
     * 跳转到修改当代丝绸管理
     */
    @RequestMapping("/modern_update/{modernId}")
    public String modernUpdate(@PathVariable Integer modernId, Model model) {
        Modern modern = modernService.selectById(modernId);
        model.addAttribute("item",modern);
        LogObjectHolder.me().set(modern);
        return PREFIX + "modern_edit.html";
    }

    /**
     * 获取当代丝绸管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return modernService.selectList(null);
    }

    /**
     * 新增当代丝绸管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Modern modern) {
        modernService.insert(modern);
        return SUCCESS_TIP;
    }

    /**
     * 删除当代丝绸管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer modernId) {
        modernService.deleteById(modernId);
        return SUCCESS_TIP;
    }

    /**
     * 修改当代丝绸管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Modern modern) {
        modernService.updateById(modern);
        return SUCCESS_TIP;
    }

    /**
     * 当代丝绸管理详情
     */
    @RequestMapping(value = "/detail/{modernId}")
    @ResponseBody
    public Object detail(@PathVariable("modernId") Integer modernId) {
        return modernService.selectById(modernId);
    }
}
